package dao.impl;

import dao.BaseDao02;
import dao.OrderItemDao;
import pojo.OrderItem;

import java.util.List;

public class OrderItemDaoImpl extends BaseDao02 implements OrderItemDao {
    @Override
    public int saveOrderItem(OrderItem orderItem) {
        String sql = "insert into t_order_item(name,count,price,total_price,order_id) " +
                "values(?,?,?,?,?);";
        return update
                (sql, orderItem.getName(), orderItem.getCount(), orderItem.getPrice(),
                        orderItem.getTotalPrice(), orderItem.getOrderId());
    }

    @Override
    public List<OrderItem> queryOrderItemsByOrderId(String orderId) {
        String sql = "SELECT `id`,`name`,`count`,`price`,`total_price` AS `totalPrice`,`order_id` AS `orderId` from t_order_item WHERE `order_id` = ?;";
        return queryForMore(sql,OrderItem.class,orderId);
    }
}
